//
//  goodsNameView.m
//  phmall
//
//  Created by admin on 2017/9/17.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "GoodsNameView.h"

@interface GoodsNameView ()

@end

@implementation GoodsNameView

-(instancetype)init{
    if (self=[super init]) {
        self.backgroundColor=[UIColor whiteColor];
        
        self.name=[[UILabel alloc] init];
//        self.name.text=@"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        self.name.font=[UIFont systemFontOfSize:15];
        self.name.numberOfLines=0;
        [self addSubview:self.name];
        
        self.like=[[UIImageView alloc]init];
        [self addSubview:self.like];
        self.like.image=[UIImage imageNamed:@"点赞"];
        
        
        self.likeNumber=[[UILabel alloc] init];
        self.likeNumber.text=@"000";
        self.likeNumber.textAlignment=NSTextAlignmentCenter;
        self.likeNumber.textColor=[UIColor blackColor];
        self.likeNumber.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.likeNumber];
        
        self.price=[[UILabel alloc] init];
//        self.price.text=@"₱9999.99";
        self.price.textColor=[UIColor orangeColor];
        self.price.font=[UIFont systemFontOfSize:20];
        [self addSubview:self.price];
    
        self.market_price=[[UILabel alloc] init];
//        self.market_price.text=@"₱9999.99";
        self.market_price.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.market_price.font=[UIFont systemFontOfSize:15];
        [self addSubview:self.market_price];
        
//        self.integral=[[UILabel alloc] init];
//        self.integral.text=@"+6666 积分";
//        self.integral.textColor=[UIColor colorWithHexString:@"#adadad"];
//        self.integral.font=[UIFont systemFontOfSize:13];
//        [self addSubview:self.integral];
        
        self.brand=[[UILabel alloc] init];
//        self.brand.text=@"品牌:XXXXX";
        self.brand.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.brand.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.brand];
        
        self.sales=[[UILabel alloc] init];
//        self.sales.text=@"库存:9999件";
        self.sales.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.sales.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.sales];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.like mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.top.offset(15);
        make.width.offset(60);
        make.height.offset(40);
    }];
    
    [self.likeNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.like).offset(0);
        make.top.equalTo(self.like);
        make.bottom.equalTo(self.like.mas_centerY);
    }];

    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).with.offset(15).priorityHigh();
        make.left.equalTo(self).with.offset(15);
        make.right.equalTo(self.like.mas_left).with.offset(-15);
    }];

    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.name);
        make.top.equalTo(self.name.mas_bottom).offset(10);
    }];
    
    [self.market_price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.price.mas_right).offset(5);
        make.bottom.equalTo(self.price).offset(-2 );
    }];
    
//    [self.integral mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.name);
//        make.top.equalTo(self.market_price.mas_bottom).offset(10);
//    }];
    
    [self.brand mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.top.equalTo(self.market_price.mas_bottom).offset(10);
    }];
    
    [self.sales mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self.brand).offset(0);
    }];
    
}
-(void)setModel:(DetailsModel *)model{
    _model=model;
    self.name.text=model.goods_name;
    self.price.text=[NSString stringWithFormat:@"₱%@",model.goods_sale_price];
    self.market_price.text=[NSString stringWithFormat:@"₱%@",model.goods_market_price];
    [self.market_price setLabelWithDelLine];
    self.brand.text=[NSString stringWithFormat:@"%@:%@",Localized(@"品牌"),model.goods_brand];
    self.sales.text=[NSString stringWithFormat:@"%@:%@%@",Localized(@"库存"),model.goods_stock,Localized(@"件")];
}
@end
